/**
 * @param {number[]} nums
 * @return {number}
 */
var totalSteps = function (nums) {
  let count = 0;
  while(1) {
    let flag = true, tempArr = [...nums], indexArr = [];
    for(let i = 1; i < tempArr.length; i++) {
      if(tempArr[i] < tempArr[i - 1]) {
        flag = false;
        indexArr.push(i);
      }
    }
    for(let i = 0; i < indexArr.length; i++) {
      nums[indexArr[i]] = undefined;
    }
    for(let i = 0; i < indexArr.length; i++) {
      const index = nums.indexOf(undefined);
      nums.splice(index, 1);
    }
    if(flag) {
      break;
    }
    count++;
  }

  return count;
};
let nums = [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11];
console.log(totalSteps(nums));
nums = [4, 5, 7, 7, 13];
console.log(totalSteps(nums));
nums = [10, 1, 2, 3, 4, 5, 6, 1, 2, 3];
console.log(totalSteps(nums));
